package com.jzo2o.orders.manager.feignClient;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.jzo2o.api.customer.AddressBookApi;
import com.jzo2o.api.customer.dto.response.AddressBookResDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Component
public class CustomerClient {

    @Resource
    private AddressBookApi addressBookApi;

    @SentinelResource(value = "getAddressBookDetail",fallback = "getAddressBookByIdFallback" ,blockHandler = "getAddressBookByIdBlockHandler")
    public AddressBookResDTO getAddressBookById(Long addressId) {
       return addressBookApi.getAddressBookById(addressId);
    }

    public AddressBookResDTO getAddressBookByIdFallback(Long id, Throwable throwable){
        log.error("非限流、熔断等导致的异常执行的降级方法，id:{},throwable:", id, throwable);
        return null;
    }

    public AddressBookResDTO getAddressBookByIdBlockHandler(Long id, BlockException blockException){
        log.error("触发限流、熔断时执行的降级方法，id:{},blockException:", id, blockException);
        return null;
    }
}
